<template>
    <el-dialog title="作废原因"
               :visible.sync="invalidReasonFlag"
               :modal-append-to-body="false"
               :close-on-click-modal="false"
               :show-close="false"
               :modal="false">
        <el-row>
            <el-col :span="24">
                <el-checkbox-group
                    v-model="invalidReasonsResult" :min="0">
                    <el-checkbox v-for="(item,index) in invalidReasons" :key="index"
                                 style="display: block; padding: 10px;"
                                 :label="item.id">
                        {{ item.reason }}
                    </el-checkbox>
                </el-checkbox-group>
            </el-col>
            <el-col style="margin-top: 30px;" :span="24">
                其他原因:
            </el-col>
            <el-col style="margin-top: 5px;" :span="24">
                <el-input v-model="invalidReasonRemark"
                          type="textarea"
                          placeholder="请输入其他原因" />
            </el-col>
            <el-col style="margin-top: 5px; text-align: right;" :span="24" />
        </el-row>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" type="primary" style="width: 80px;" @click="returnInvalidReason">保存</el-button>
            <el-button size="small" type="primary" style="width: 80px;" @click="closeInvalidReason">取消</el-button>
        </span>
    </el-dialog>
</template>

<script>
// import  {DictionariesGroup} from '@/api/resourceApi';
export default {
    name: 'InvalidReasonList',
    props: {
        invalidReasonFlag: Boolean
    },
    data() {
        return {
            invalidReasons: [],
            invalidReasonsResult: [],
            invalidReasonRemark: ''

        };
    },
    mounted() {
        DictionariesGroup({Group: '2004'}).then(res => {
            var array = [];
            res.res.SiteMap.forEach(x => {
                array.push({
                    id: x.sysdict_code,
                    reason: x.sysdict_name
                });
            });
            this.invalidReasons = array;
        }).catch(err => {
            console.log(err);
        });
    },
    methods: {
        returnInvalidReason() {
            if (this.clickTooFast()) return;
            var invalidReason = '';
            this.invalidReasonsResult.forEach(x => {
                invalidReason += x + ',';
            });
            if (invalidReason != '')
                invalidReason = invalidReason.substr(0, invalidReason.length - 1);
            var result = {
                invalidReasonsResult: invalidReason,
                invalidReasonRemark: this.invalidReasonRemark
            };
            this.$emit('returnInvalidReason', result);
        },
        closeInvalidReason() {
            this.$emit('closeInvalidReason', false);
        }
    }
};
</script>

